<?php
/**
 * Created by PhpStorm.
 * User: gxk
 * Date: 2019/5/7
 * Time: 19:34
 */
?>
<script src="/data/js/jquery.js"></script>
<input type="text" id="content" name="content">
<input type="button" value="发送">
<script>
    $(function(){
        var wsl= 'ws://45.40.207.184:9502';
        ws = new WebSocket(wsl);
        console.log(ws);
        $('input[type="button"]').on('click',function(){
            ws.send($('[name="content"]').val());
        });

        ws.onopen = function(event) {
            console.log('连接成功!');
            console.log(event);
//            socket.send("来了,老弟!\n");
        };
        ws.onmessage = function(event) {//当客户端收到服务端发来的消息时，会触发onmessage事件，参数event.data中包含server传输过来的数据
            var content = event.data;//获取消息
            console.log("客户端回复 :"+content);
        };
        ws.onclose = function(evt)
        {
            console.log("WebSocketClosed!");
        };
        ws.onerror = function(evt)
        {
            console.log("WebSocketError!");
        };
    });

</script>

